const axios = require('./axios');
var url__ = '';
let musicMain = [];
axios({
  method: "get",
  url: url__ || 'https://hifini.com/forum-1.htm',
})
  .then(function (res) {
    if (res.status === 200) {
      let data = res.data;
      var reg = /tap.{1,3}\".*?<img.*?<a\shref=\"(.*?)\"\s?\>(.*?)《(.*?)》.{10,25}<\/a>.*?d-flex/gims;
      var resres = data.match(reg);
      if (!resres || resres.length == 0) {
        return musicMain
      };
      resres.forEach(element => {
        let i = /\<a.*?href=\"(.*?)\"\s?\>(.*?)《(.*)》.*?\<\/a\>/.exec(element);
        musicMain.push("https://hifini.com/" + i[1], i[2], i[3])
      });
      return musicMain
    } else {
      return musicMain
    }
  })
  .catch(function (error) {
    console.log('', error)
  });


function searchFn(value) {
  let s = value.trim();
  if (!s) return "https://hifini.com/";
  s = encodeURIComponent(s);
  s = s.replace(/_/g, "%5f");
  s = s.replace(/\-/g, "%2d");
  s = s.replace(/\./g, "%2e");
  s = s.replace(/\~/g, "%7e");
  s = s.replace(/\!/g, "%21");
  s = s.replace(/\*/g, "%2a");
  s = s.replace(/\(/g, "%28");
  s = s.replace(/\)/g, "%29");
  s = "https://hifini.com/search-" + s.replace(/\%/g, "_") + "-1.htm";
  return s;
}